package com.qingneng.budget.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.qingneng.budget.vo.Userinfo;

public class LoginCheck {
	public static boolean check(HttpServletRequest request,HttpServletResponse response){
		HttpSession session = request.getSession();
		if(session.getAttribute("userinfo")==null){
			request.setAttribute("auth", "");
			return false;
		}
		return true;
	}
	
	public static boolean logout(HttpServletRequest request,HttpServletResponse response){
		HttpSession session = request.getSession();
		if(session.getAttribute("userinfo")!=null){
			session.setAttribute("userinfo",null);
		}
		return true;
	}
	
	public static boolean isAdmin(HttpServletRequest request,HttpServletResponse response){
		HttpSession session = request.getSession();
		if(session.getAttribute("userinfo")!=null){
			Userinfo userinfo = (Userinfo)session.getAttribute("userinfo");
			//管理员
			if(userinfo.getExtend1()!=null&&userinfo.getExtend1().equals("0")){
				return true;
			}
		}
		return false;
	}
}
